import {get,post,put,setTokens} from "../httpx";
import {RecordApi} from "../urls";

const languageMap = {
  "java":1,
  "cpp":2,
  "go":3
}

const languageNameMap = {
  1:"Java",
  2:"Cpp",
  3:"Go"
}

const getAll = async () =>{
  return await get(RecordApi.getAll,{})
}

const getById = async (id) => {
  return await get(RecordApi.getById, {id})
}

const getStatus = async (id) => {
  return await get(RecordApi.getStatusById,{id} )
}

const submit =  record => post(RecordApi.submit,record)

const getSuccessStatistic = ()=>get(RecordApi.geySuccessStatistic)

const getLanguageId = (code)=>languageMap[code]
const getLanguageName = (id)=>languageNameMap[id]

const statusDetailList = ['判题中','判题通过','内存超限','时间超限','输出超限','文件错误','运行错误','进程关闭','内部错误','编译错误','答案错误']
const statusTagList = ['primary','success','warning','warning','warning','info','warning','info','info','primary','danger']
const statusColorList = ['#4e72b8','#1d953f','#f58220','#ae6642','#87481f','#b36d41','#412f1f','#412f1f','#412f1f','#121a2a','#d71345']

const getStatusDetail = id => statusDetailList[id]

const getStatusTag = id => statusTagList[id]

const getStatusColor = id => statusColorList[id]

export const Record = {
  getAll,getById,getStatus,submit,getLanguageId,getStatusDetail,getLanguageName,getStatusTag,getStatusColor,getSuccessStatistic
}
